#coding:utf-8
import time
from common.FuyuanwaiConf import FuyuanwaiConf

__author__ = 'yangxianming'

import json
import requests


def case():
    #1-100福利金买单操作
    #如果返回授权失败 可能是cookie中的SERVERID后面两个时间搓过期
    api_list = ["efuli.welfarepoint.benefits"]
    fuyuanwaiConf = FuyuanwaiConf()
    test_url = fuyuanwaiConf.proDomain + "/pointweb/point"

    arr = []
    for x in range(1, 25):
        arr.append(x)
    arr.append(200)
    # arr.append(300)
    # arr.append(400)
    # arr.append(500)

    tf = True
    err_info = {"err_amount": ""}
    for i in arr:
        err_count = 0
        while True:
            # time.sleep(1)
            money = str(i * 100)
            print(money)
            body = {"money":money,"corpUserId":"fdd5a9413709463893d2a713e07abaca","corpId":"382aa7ec0d0143828843c0dbe88fcfe8","request_id":1560998649993}
            p ={"action":api_list[0],"body":body}
            r = requests.post(test_url, data=json.dumps(p), headers=fuyuanwaiConf.proHeaders)
            r_json = r.json()
            print("这个是接口" + api_list[0] + "返回的全部参数\n", r_json)
            return_code = r_json["return_code"]
            print("返回参数return_code值", return_code)
            if return_code == "00":
                break
            if money in err_info.keys():
                err_info.update({money: err_info.get(money) + ";" + return_code})
            else:
                err_info.update({money: return_code})
            err_count += 1
            if err_count > 20:
                err_info.update({"err_amount": err_info.get("err_amount") + ";" + money})
                tf = False
                break


    #结果判断

    #定义预期描述
    expect_result = "预期结果:err_amountc="

    #返回测试结果 第一个参数:True or False    第二个参数测试结果描述
    return tf, [err_info, expect_result]

# case()